//
//  ByViewStoreHeader.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/6.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewStoreHeader.h"

@implementation ByViewStoreHeader
{
    UIImageView *_iconView;             // 商家图标
    UILabel     *_distanceLabel;        // 距离
    UILabel     *_nameLabel;            // 商家名称
    UILabel     *_sellAmountLabel;      // 在售商品数量
    
    UIImageView *_addressImageView;     // 地址
    UILabel     *_addressLabel;         // 地址
}
- (instancetype)init {
    
    if (self = [super init]) {
        
        self.backgroundColor = [UIColor brownColor];
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    // 图标
    _iconView = [UIImageView new];
    _iconView.image = [UIImage imageWithColor:[UIColor redColor]];
    [self addSubview:_iconView];
    
    // 距离
    _distanceLabel = [[UILabel alloc] init];
    _distanceLabel.text = @"300m";
    _distanceLabel.font = FONT(15);
    _distanceLabel.textAlignment = NSTextAlignmentRight;
    _distanceLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:_distanceLabel];
    
    // 商家名称
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.numberOfLines = 2;
    _nameLabel.text = @"耐克旗舰店";
    _nameLabel.font = FONT(16);
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    _nameLabel.textColor = [UIColor whiteColor];
    [self addSubview:_nameLabel];
    
    // 在售商品数量
    _sellAmountLabel = [[UILabel alloc] init];
    _sellAmountLabel.text = @"在售商品：1234件";
    _sellAmountLabel.font = FONT(14);
    _sellAmountLabel.textAlignment = NSTextAlignmentLeft;
    _sellAmountLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:_sellAmountLabel];
    
    // 查看地址图片
    _addressImageView = [UIImageView new];
    _addressImageView.image = [UIImage imageNamed:@"取消关注"];
    [self addSubview:_addressImageView];
    
    // 查看地址文本
    _addressLabel = [[UILabel alloc] init];
    _addressLabel.text = @"查看地址";
    _addressLabel.font = FONT(14);
    _addressLabel.textAlignment = NSTextAlignmentRight;
    _addressLabel.textColor = BY_GOLD_COLOR;
    [self addSubview:_addressLabel];
    
    
    
    // 布局
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(@0);
        make.width.equalTo(_iconView.mas_height);
    }];
    [_distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@10);
        make.right.equalTo(@-10);
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconView.mas_right).offset(10);
        make.bottom.equalTo(_iconView.mas_centerY).offset(-5);
        make.right.lessThanOrEqualTo(_distanceLabel.mas_left).offset(-10);
    }];
    [_sellAmountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nameLabel);
        make.top.equalTo(_iconView.mas_centerY).offset(5);
        make.width.equalTo(_nameLabel);
    }];
    [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_distanceLabel);
        make.bottom.equalTo(@-10);
    }];
    [_addressImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.right.equalTo(_addressLabel.mas_left).offset(-5);
        make.centerY.equalTo(_addressLabel);
    }];
}

@end
